package com.cc.visitor.controller;

import com.cc.alltype.ResponseResult;
import com.cc.visitor.service.KaptchaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.time.LocalDateTime;
import java.util.Map;

/**
 * @author chanchaw
 * @create 2024-10-10 12:58
 */
@CrossOrigin
@RestController
@RequestMapping("/kaptcha")
public class KaptchaController {
    @Autowired
    private KaptchaService service;
    @GetMapping("/createKaptchaImg")
    public ResponseResult createKaptchaImg() throws IOException {
        Map<String, String> ret = service.createKaptchaImg();
        return ResponseResult.ok(ret);
    }
    @GetMapping("/login/getVerifyCode")
    public void getVerifyCode(String loginKey,
                              HttpServletRequest httpServletRequest,
                              HttpServletResponse httpServletResponse) {
        try {
            //log.warn("query verify Code" + loginKey);
            service.getVerifyCode(loginKey, httpServletRequest, httpServletResponse);
        } catch (Exception e) {
            //log.error("get verify Code failed :", e);
        }
    }

    @GetMapping("/now")
    public ResponseResult getNowtime(){
        return ResponseResult.ok(LocalDateTime.now());
    }
}
